package com.wx_shop.api;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@SpringBootApplication
public class AppMainStarter extends WebMvcConfigurerAdapter {
	
	public static ApplicationContext applicationContext;
	
	private static Logger LOG = LoggerFactory.getLogger(AppMainStarter.class);
	
	public static void main(String[] args) {
		
		LOG.info("App to Start ...");
		applicationContext = SpringApplication.run(AppMainStarter.class, args);
	}

	@Override
	public void addViewControllers(ViewControllerRegistry registry) {
		registry.addRedirectViewController("/", "/html/index.html");
	}
	
	/**
	 * 设置跨域
	 */
	@Override
	public void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/**")
				.allowCredentials(true)
				.allowedHeaders("*")
				.allowedOrigins("*")
				.allowedMethods("*");
 
	}

}
